@extends('layouts.default')

@section('title', '教研活动')

@push('scripts')
<script src="{{ asset('lib/xm-select-v1.2.4/xm-select.js')}}"></script>
<script>
    layui.use(['layer','form','table','laytpl','laydate','element','laypage','upload'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var element = layui.element;
        var laypage = layui.laypage;
        var upload = layui.upload;
        var cxmDemo;
        var pxmDemo;
        var xmCourseDemo;
        var PageId = "{{request()->get('id',0)}}";
        var clFiles = [];
        var perPage = 10;
        var totalNum = 0;
        var LiveParam = {};
        var ScaleSelectData;
        var HomeworkFormData = [];

        //自定义验证规则
        form.verify({
            otherReq: function(value,item){
                var $ = layui.$;
                var verifyName=$(item).attr('name')
                , verifyType=$(item).attr('type')
                ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
                ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
                ,isTrue= verifyElem.is(':checked')//是否命中校验
                ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
                if(!isTrue || !value){
                    //定位焦点
                    focusElem.css(verifyType=='radio'?{"color":"#FF5722"}:{"border-color":"#FF5722"});
                    //对非输入框设置焦点
                    focusElem.first().attr("tabIndex","1").css("outline","0").blur(function() {
                        focusElem.css(verifyType=='radio'?{"color":""}:{"border-color":""});
                    }).focus();
                    return '必填项不能为空';
                }
            }
        });

        renderSelect();

        laydate.render({
            elem: '#begin-date'
            ,type: 'date'
        });
        laydate.render({
            elem: '#end-date'
            ,type: 'date'
        });
        //日期时间范围
        laydate.render({
            elem: '#live-date'
            ,type: 'datetime'
            ,range: true
        });

        //下拉框初始化
        async function renderSelect(){
            await toGetScaleSelect();
            await renderDicSelect2();
            await renderCoursesSelect();
            await renderDicSelect();
            await renderTermSelect();
            await renderCompere();
            await renderParticipants();
            pageInit();
        }

        // 量表选择框数据
        function toGetScaleSelect() {
            return new Promise((resolve) => {
                getScaleSelect({type: 3},function(res){
                    if(res.code == 1){
                        ScaleSelectData = res.data;
                        renderScaleSelect();

                        resolve();
                    }
                });
            });
        }

        //字典下拉框数据渲染
        function renderDicSelect2() {
            return new Promise((resolve) => {
                getDicListByCodes({'diccode': ['JYZYLX']}, function (res){
                    if(res.code === 1) {
                        let data = res.data;

                        for(var k in data) {
                            let key = k.toLowerCase();
                            $('[data-role='+key+'List]').empty().append('<option value="">请选择</option>');
                            let d = data[k];
                            homework_type = d;
                            for (var i in d) {
                                $('[data-role='+key+'List]').append('<option value="' + d[i].itemcode + '">' + d[i].itemname + '</option>');
                            }
                        }

                        form.render();

                        resolve();
                    }
                });
            });
        }
        //学科下拉框数据渲染
        function renderCoursesSelect() {
            return new Promise((resolve) => {
                getDictionaryXmSelect({'diccode': ['SUBJECT']},function(res){
                    if(res.code == 1){
                        xmCourseDemo = xmSelect.render({
                            el: '#courses',
                            autoRow: true,
                            filterable: true,
                            tree: {
                                show: true,
                                showFolderIcon: true,
                                showLine: true,
                                indent: 20,
                                expandedKeys:false
                            },
                            direction: 'down',
                            height: '480px',
                            name:'course_item',
                            layVerify: 'required',
                            layVerType: 'msg',
                            layReqText:'年级不能为空',
                            theme: {
                                color: '#2d8cf0',
                            },
                            model: {
                                label: {
                                    type: 'block',
                                    block: {
                                        //最大显示数量, 0:不限制
                                        showCount: 0,
                                        //是否显示删除图标
                                        showIcon: false,
                                    }
                                }
                            },
                            disabled:true,
                            searchTips:'关键字搜索',
                            data: function(){
                                return res.data.SUBJECT
                            }
                        })

                        return resolve();
                    }
                });
            });
        }

        //字典下拉框数据渲染
        function renderDicSelect() {
            return new Promise((resolve) => {
                getDicListByCodes({'diccode': ['HDLB']}, function (res){
                    if(res.code === 1) {
                        let data = res.data;

                        for(var k in data) {
                            $('[data-role='+k+'List]').empty().append('<option value="">请选择</option>');
                            let d = data[k];
                            for (var i in d) {
                                $('[data-role='+k+'List]').append('<option value="' + d[i].itemcode + '">' + d[i].itemname + '</option>');
                            }
                        }

                        form.render();

                        resolve();
                    }
                });
            });
        }

        //学期下拉框数据渲染
        function renderTermSelect() {
            return new Promise((resolve) => {
                getTermData({},function(res){
                    if(res.code == 1){
                        $('[data-role=termList]').empty().append('<option value="">请选择</option>');
                        for(var i in res.data){
                            $('[data-role=termList]').append('<option value="'+res.data[i].id+'">'+res.data[i].title+'</option>');
                        }

                        form.render('select');

                        resolve();
                    }
                });
            });
        }

        //主讲教师下拉框数据渲染
        function renderCompere() {
            return new Promise((resolve) => {
                getParticipantsData({},function(res){
                    if(res.code == 1){
                        cxmDemo = xmSelect.render({
                            el: '#cter',
                            autoRow: true,
                            filterable: true,
                            tree: {
                                show: true,
                                showFolderIcon: true,
                                showLine: true,
                                indent: 20,
                                expandedKeys:false
                            },
                            direction: 'down',
                            filterable: true,
                            height: 'auto',
                            name:'compere',
                            layVerify: 'required',
                            layVerType: 'msg',
                            layReqText:'主讲教师不能为空',
                            theme: {
                                color: '#2d8cf0',
                            },
                            model: {
                                label: {
                                    type: 'block',
                                    block: {
                                        //最大显示数量, 0:不限制
                                        showCount: 0,
                                        //是否显示删除图标
                                        showIcon: false,
                                    }
                                }
                            },
                            disabled:true,
                            searchTips:'关键字搜索',
                            data: function(){
                                return res.data
                            }
                        })

                        return resolve();
                    }
                });
            });
        }
        //参与教师下拉框数据渲染
        function renderParticipants() {
            return new Promise((resolve) => {
                getParticipantsData({},function(res){
                    if(res.code == 1){
                        pxmDemo = xmSelect.render({
                            el: '#pter',
                            autoRow: true,
                            filterable: true,
                            tree: {
                                show: true,
                                showFolderIcon: true,
                                showLine: true,
                                indent: 20,
                                expandedKeys:false
                            },
                            direction: 'down',
                            filterable: true,
                            height: 'auto',
                            name:'participant',
                            layVerify: 'required',
                            layVerType: 'msg',
                            layReqText:'参与教师不能为空',
                            theme: {
                                color: '#2d8cf0',
                            },
                            model: {
                                label: {
                                    type: 'block',
                                    block: {
                                        //最大显示数量, 0:不限制
                                        showCount: 0,
                                        //是否显示删除图标
                                        showIcon: false,
                                    }
                                }
                            },
                            disabled:true,
                            searchTips:'关键字搜索',
                            data: function(){
                                return res.data
                            }
                        })

                        return resolve();
                    }
                });
            });
        }

        // 文件显示
        function fileShow(files) {
            let showFiles = {};
            layui.each(files, function(i, d) {
                if(d.field) {
                    clFiles.push(d.file_origin);

                    if (showFiles[d.field]) {
                        showFiles[d.field].push(d);
                    } else {
                        showFiles[d.field] = [d];
                    }
                } else {
                    if (showFiles['cl']) {
                        showFiles['cl'].push(d);
                    } else {
                        showFiles['cl'] = [d];
                    }
                }
            });

            layui.each(showFiles, function(f, d) {
                let fileShowTpl = fileShowDemo.innerHTML
                    ,fileShow = document.getElementById('file-show-'+f);

                laytpl(fileShowTpl).render(d, function(html){
                    fileShow.innerHTML = html;
                });
            });

            renderLinkSelectedData();
        }
        //数据渲染
        function pageInit(){
            getTeaActivityOne({id:PageId}, function(res) {
                if(res.code === 1) {
                    let Activity = res.data;
                    let TeachingActivity = Activity.teaching_activity;
                    let oldLevel = Activity.level && Activity.level_array.length > 0 ? Activity.level_array[0].selectValue : '校级';

                    form.val('infoForm', {
                        'id': PageId,
                        'data_version_id': Activity.data_version_id,
                        'name': Activity.name,
                        'begin_date': Activity.begin_date,
                        'end_date': Activity.end_date,
                        'activity_level': TeachingActivity.activity_level ? TeachingActivity.activity_level : oldLevel,
                        //'course': Activity.course_set[0].optionId,
                        'teaching_type': TeachingActivity.teaching_type,
                        'activity_type': TeachingActivity.activity_type,
                        // 'video_link': TeachingActivity.video_link,
                        'is_open': TeachingActivity.is_open,
                        'place': TeachingActivity.place,
                        'content': TeachingActivity.content
                    });

                    if(Activity.course && Activity.course_set.length > 0) {
                        let courseSelected = [];
                        layui.each(Activity.course_set, function(i, d) {
                            courseSelected.push(d.optionId);
                        });
                        xmCourseDemo.setValue(courseSelected);
                    }

                    if(TeachingActivity.video_link) {
                        $("#video-link").attr('href', TeachingActivity.video_link).html(TeachingActivity.video_link);
                    }

                    //参与教师
                    cxmDemo.setValue(Activity.participants_users.pere);
                    pxmDemo.setValue(Activity.participants_users.pant);
                    //直播
                    if(TeachingActivity.live_id) {
                        let lHtml = '<span style="line-height: 42px;display: inline-block;max-width: 90%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">'+TeachingActivity.live.name+'</span>'
                        $("#live-show").append(lHtml);

                        //作业参考材料处理
                        $('#ckcl-show').append('<input type="checkbox" id="checkbox-live-id" name="live_id" lay-skin="primary" value="'+TeachingActivity.live.id+'" title="'+TeachingActivity.live.name+'">');
                    }
                    //文件
                    if(Activity.proof_material_array.length){
                        fileShow(Activity.proof_material_array);
                    }

                    //作业渲染
                    if(Activity.homework) {
                        HomeworkFormData = Activity.homework;
                        renderHomework();
                    }

                    form.render();
                } else {
                    layer.msg('无数据记录', {time: 2000, icon: 5});
                }
            });
        }
        function renderLinkSelectedData(){
            if(clFiles.length > 0) {
                for(i in clFiles) {
                    if(clFiles[i]) {
                        $('#ckcl-show').append('<input type="checkbox" id="li'+clFiles[i].id+'" name="link_id[]" lay-skin="primary" value="'+clFiles[i].id+'" title="'+clFiles[i].file_name+'">');
                    }
                }

                form.render();
            }
        }

        // 添加作业
        $("#add-homework").click(function() {
            layer.ready(function() {
                var index = layer.load(2);
                var homeworkLayer = layer.open({
                    type: 1,
                    title: '添加作业',
                    content: $('#homeworkTerm'),
                    area: ['70%', '60%'],
                    success: function() {
                        form.val('homeworkForm', {
                            'activity_id': PageId,
                            'homework_id':'',
                            'form_index':'',
                        });

                        //处理多选框title提示
                        $('.layui-form-checkbox span').each(function(){
                            $(this).attr('title', $(this).html());
                        });
                    },
                    cancel: function() {
                        //右上角关闭回调
                        $('#homework-form')[0].reset();
                        //return false 开启该代码可禁止点击该按钮关闭
                    }
                });
                // layer.full(homeworkLayer);
                layer.close(index);
            });
            return false;
        });
        $("#sub-homework").on('click', function() {
            var data = form.val("homeworkForm");

            addTeaActivityHomework(data, function(res){
                if(res.code == '1'){
                    layer.msg(res.msg,{icon: 6,time: 3000}, function() {
                        $('#homework-form')[0].reset();
                        //编辑的提交
                        if(HomeworkFormData[data.form_index]) {
                            HomeworkFormData[data.form_index] = res.data;
                        } else {
                            HomeworkFormData.push(res.data);
                        }

                        renderHomework();
                        layer.closeAll();
                    });
                }else{
                    layer.msg(res.msg, {icon: 5,shift : 6});
                }
            });
        });
        // 渲染作业表单
        function renderHomework() {
            let hwShowTpl = hwDemo.innerHTML
                ,hwShow = document.getElementById('hw-content');

            laytpl(hwShowTpl).render(HomeworkFormData, function(html){
                hwShow.innerHTML = html;
            });
            renderHomeworkSelect();
            renderScaleSelect();
            layui.each(HomeworkFormData, function(i, hw) {
                console.log(hw)
                if(hw) {
                    form.val('hwForm'+i, {
                        "demand": hw.demand,
                        "scale_id": hw.scale_id,
                        "is_upload": hw.is_upload,
                        "type":hw.type,
                        "is_describe": hw.is_describe,
                    });
                }
            });

            form.render();

            //处理多选框title提示
            $('#hw-content').find('.layui-form-checkbox span').each(function(){
                $(this).attr('title', $(this).html());
            });
        }

        function renderHomeworkSelect(){
            $('[data-role=homework_typeList]').empty().append('<option value="">请选择</option>');
            for (var i in homework_type) {
                $('[data-role=homework_typeList]').append('<option value="' + homework_type[i].itemcode + '">' + homework_type[i].itemname + '</option>');
            }
        }

        window.deleteHomework = function(_this) {
            var fi = _this.attr('form-index');
            var id = _this.attr('item-id');
            delete HomeworkFormData[fi];

            delTeaActivityHomework({id: id}, function(res){
                if(res.code == '1'){
                    layer.msg('删除成功！',{icon: 6,time: 2000}, function() {
                        _this.parent().parent().parent('.layui-card').remove();
                    });
                }else{
                    layer.msg(res.msg, {icon: 5,shift : 6});
                }
            });

        }
        window.editHomework = function(_this) {
            var fi = _this.attr('form-index');
            var formData = HomeworkFormData[fi];

            var index = layer.load(2);
            var ehomeworkLayer = layer.open({
                type: 1,
                title: '编辑作业',
                content: $('#homeworkTerm'),
                area: ['70%', '60%'],
                success: function() {
                    form.val('homeworkForm', {
                        "live_id": formData.live_id,
                        "demand": formData.demand,
                        "scale_id": formData.scale_id,
                        "is_upload": formData.is_upload,
                        "is_describe": formData.is_describe,
                        "activity_id": formData.activity_id,
                        "homework_id": formData.id,
                        'form_index': fi,
                        'type':formData.type,
                    });

                    let lks = formData.link_set;
                    if(lks.length > 0) {
                        for(l in lks) {
                            $("#li"+lks[l].id).prop('checked', true);
                        }
                    }

                    form.render();
                    // //处理多选框title提示
                    $('.layui-form-checkbox span').each(function(){
                        $(this).attr('title', $(this).html());
                    });
                },
                cancel: function() {
                    //右上角关闭回调
                    $('#homework-form')[0].reset();
                    //return false 开启该代码可禁止点击该按钮关闭
                }
            });
            // layer.full(homeworkLayer);
            layer.close(index);
        }
        function renderScaleSelect(){
            $('[data-role=scaleList]').empty().append('<option value="">请选择</option>');
            for(var i in ScaleSelectData){
                $('[data-role=scaleList]').append('<option value="'+ScaleSelectData[i].id+'">'+ScaleSelectData[i].name+'</option>');
            }

            form.render('select');
        }

        $(".cancel-btn").click(function(){
            layer.closeAll();
        });
    });
</script>
@endpush

@section('content')
<style>
    .opt-panel{padding: 10px;}
    .panel-title h3{margin-bottom: 20px;font-weight: 800;}

    .opt-form{padding: 20px 5px 0;}
    .opt-area{display: flex;flex-direction: row-reverse;padding: 10px 20px;margin-bottom: 20px;}
    .opt-area button, .back-btn{margin-left: 10px;}
    .opt-form .layui-row{margin-bottom: 10px;}

    .resourse-row{min-height: 200px;}
    #homework-row{padding: 0 5px;}
    .opt-add-area{display: grid;grid-template-columns: 70% 30%;}
    .opt-add-area #add-homework{margin-right: 20px;float: right;}

    .live-btn-container{margin-left: 80%;}
    .cancel-btn{margin-left: 10px;}

    .hw-content{display: grid;grid-template-columns: 50% 50%;min-height: 300px;}
    .hw-content .layui-card{margin: 15px;}
    .hw-content .layui-card-header{display: grid;grid-template-columns: 70% 30%;}
    .hw-content .layui-card-body{padding: 0 15px;}
    .hw-content .layui-card-header h3{font-weight: 800; color: #7397ed;}
    .hw-content .layui-card-header .btn-area button{margin-top: 10px;margin-left: 12px;float: right;}

    #ckcl-show .layui-form-checkbox span,.link-show .layui-form-checkbox span{max-width: 120px;}
    #video-link{display: inline-block;line-height: 42px;}
</style>

<div class="layui-row">
    <div class="layui-panel opt-panel">
        <form class="layui-form opt-form" action="" id="info-form" lay-filter="infoForm">
            <div class="layui-row">
                <div class="panel-title">
                    <h3>教研活动 - 基本设置</h3>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">学年学期：</label>
                        <div class="layuik-input-inline">
                            <select disabled class="data-version-id" name="data_version_id" lay-filter="termList" data-role="termList" lay-verify="required" lay-reqText="不能为空"></select>
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label">教研名称：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="text" name="name" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">教研形式：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="radio" name="teaching_type" title="在线" value="1" class="layui-radio">
                            <input disabled type="radio" name="teaching_type" title="离线" value="2" class="layui-radio">
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label">活动类别：</label>
                        <div class="layuik-input-inline">
                            <select disabled name="activity_type" lay-filter="hdlbList" data-role="hdlbList" lay-verify="required" lay-reqText="不能为空"></select>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">学科：</label>
                        <div class="layuik-input-inline">
                            <div type="text" id="courses" class="xm-select-courses"></div>
                            <!-- <select disabled name="course" lay-filter="subjectList" data-role="subjectList" lay-verify="required" lay-reqText="不能为空"></select> -->
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label">级别：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="activity_level" required lay-verify="required" placeholder="请输入" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">公开课：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="radio" name="is_open" title="是" value="1" lay-verify="otherReq" class="layui-radio">
                            <input disabled type="radio" name="is_open" title="否" value="2" lay-verify="otherReq" class="layui-radio">
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label">地址：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="text" name="place" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">开始日期：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="text" name="begin_date" id="begin-date" required lay-verify="required" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label">结束日期：</label>
                        <div class="layuik-input-inline">
                            <input disabled type="text" name="end_date" id="end-date" required lay-verify="required" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">教研内容：</label>
                        <div class="layuik-input-inline">
                            <textarea disabled name="content" id="" rows="3" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">主讲教师：</label>
                        <div class="layuik-input-inline">
                            <div type="text" id="cter" class="xm-select-demo"></div>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">参与教师：</label>
                        <div class="layuik-input-inline">
                            <div type="text" id="pter" class="xm-select-demo"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="layui-row resourse-row">
                <div class="panel-title">
                    <h3>教研活动 - 教研资源</h3>
                </div>
                <!-- <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">直播资源：</label>
                        <div class="layuik-input-inline">
                            <div id="live-show"></div>
                        </div>
                    </div>
                </div> -->
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">材料：</label>
                        <div class="layuik-input-inline">
                            <div id="file-show-cl"></div>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">视频链接：</label>
                        <div class="layuik-input-inline">
                            <!-- <input type="text" name="video_link" autocomplete="off" class="layui-input"> -->
                            <a href="javascript:;" target="_blank" id="video-link"></a>
                        </div>
                    </div>
                </div>
            </div>
        </form>

        <div class="layui-row" id="homework-row">
            <div class="panel-title opt-add-area">
                <h3>教研活动 - 作业设置</h3>
                <div class="btn-area">
                    <button type="button" class="layui-btn layui-btn-normal" id="add-homework">添加作业</button>
                </div>
            </div>

            <div class="hw-content" id="hw-content"></div>
        </div>

        <div class="layui-row">
            <div class="opt-area">
                <a href="javascript:history.go(-1);" class="layui-btn layui-btn-primary back-btn">返回</a>
            </div>
        </div>
    </div>
</div>

<!-- 添加编辑作业 -->
<div id="homeworkTerm" style="display: none;">
    <div class="layui-row">
        <div class="layui-panel opt-panel">
            <form class="layui-form opt-form" action="" id="homework-form" lay-filter="homeworkForm">
                <div class="layui-row">
                    <div class="layuik-form-item">
                        <div class="layuik-inline">
                            <label class="layuik-form-label">参考材料：</label>
                            <div class="layuik-input-inline" id="ckcl-show"></div>
                        </div>
                    </div>
                    <div class="layuik-form-item">
                        <div class="layuik-inline">
                            <label class="layuik-form-label">作业要求：</label>
                            <div class="layuik-input-inline">
                                <textarea name="demand" id="" rows="3" class="layui-textarea" placeholder="请输入"></textarea>
                            </div>
                        </div>
                    </div>

                    <div class="layuik-form-item">
                        <div class="layuik-inline">
                            <label class="layuik-form-label">类型：</label>
                            <div class="layuik-input-inline">
                                <select name="type" lay-filter="homework_typeList" data-role="homework_typeList" class="homework_type"></select>
                            </div>
                        </div>
                    </div>
                    <div class="layuik-form-item layuik-columns-two">
                        <div class="layuik-inline">
                            <label class="layuik-form-label">上传附件：</label>
                            <div class="layuik-input-inline">
                                <input type="radio" name="is_upload" title="是" value="1" class="layui-radio">
                                <input type="radio" name="is_upload" title="否" value="2" class="layui-radio">
                            </div>
                        </div>
                    </div>
                    <div class="layuik-form-item layuik-columns-two">
                        <div class="layuik-inline">
                            <label class="layuik-form-label">总结性描述：</label>
                            <div class="layuik-input-inline">
                                <input type="radio" name="is_describe" title="是" value="1" class="layui-radio">
                                <input type="radio" name="is_describe" title="否" value="2" class="layui-radio">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-row">
                    <div class="opt-area">
                        <a href="javascript:;" class="layui-btn layui-btn-primary cancel-btn">取消</a>
                        <button class="layui-btn layui-btn-normal" type="button" id="sub-homework">确定</button>
                        <input type="hidden" name="activity_id" value="">
                        <input type="hidden" name="homework_id" value="">
                        <input type="hidden" name="form_index" value="">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/html" id="hwDemo">
    @{{#  layui.each(d, function(index, item){ }}
    @{{#  if(item){ }}
    <div class="layui-card">
        <div class="layui-card-header">
            <h3>作业@{{index+1}}</h3>
            <div class="btn-area">
                <button type="button" class="layui-btn layui-btn-xs layui-btn-primary layui-border-red" form-index="@{{index}}" item-id="@{{item.id}}" onclick="deleteHomework($(this))">删除</button>
                <button type="button" class="layui-btn layui-btn-xs layui-btn-primary layui-border-blue" form-index="@{{index}}" item-id="@{{item.id}}" onclick="editHomework($(this))">编辑</button>
            </div>
        </div>
        <div class="layui-card-body">
            <form class="layui-form opt-form" action="" id="hw-form@{{index}}" lay-filter="hwForm@{{index}}">
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">参考材料：</label>
                        <div class="layuik-input-inline link-show">
                        @{{#  if(item.live_id){ }}
                            <input type="checkbox" name="live_id" lay-skin="primary" value="@{{item.live_id}}" title="@{{item.live.name}}" disabled checked>
                        @{{#  } }}
                        @{{#  layui.each(item.link_set, function(i, l){ }}
                            <input type="checkbox" name="link_id[]" lay-skin="primary" value="@{{l.id}}" title="@{{l.file_name}}" disabled checked>
                        @{{#  }); }}
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">作业要求：</label>
                        <div class="layuik-input-inline">
                            <textarea name="demand" id="" rows="3" class="layui-textarea" placeholder="请输入" disabled></textarea>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">类型：</label>
                        <div class="layuik-input-inline">
                            <select name="type" lay-filter="homework_typeList" data-role="homework_typeList">
                                @{{item.htmlData}}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">上传附件：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" name="is_upload" title="是" value="1" class="layui-radio" disabled>
                            <input type="radio" name="is_upload" title="否" value="2" class="layui-radio" disabled>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">总结性描述：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" name="is_describe" title="是" value="1" class="layui-radio" disabled>
                            <input type="radio" name="is_describe" title="否" value="2" class="layui-radio" disabled>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
    @{{#  } }}
    @{{#  }); }}
</script>

<script id="fileShowDemo" type="text/html">
<ul>
@{{#  layui.each(d, function(index, item){ }}
@{{#  if(item){ }}
    <li style="min-width: 200px;margin: 13px 5px;">
        <a style="color: #0e90d2;" target="_blank" title="@{{item.file_info.file_name}}" href="@{{item.file_info.file_dir}}@{{item.file_info.file_path}}">
            <span style="display: inline-block;max-width: 90%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">@{{item.file_info.file_name}}</span>
        </a>
        <a style="color:#74B8FF" href="@{{item.file_info.file_dir}}@{{item.file_info.file_path}}" download="@{{item.file_info.file_name}}">
            <span class="icon pear-icon pear-icon-download" style="color:#74B8FF;margin-left:10px;"></span>
        </a>
    </li>
@{{#  } }}
@{{#  }); }}
</ul>
</script>
@endsection
